<template>
  <div class="banner-header">
    <router-link tag="div" to="/" v-show="showBackBtn" class="back-abs"><span class="iconfont icon-back">&#xe743;</span></router-link >
    <div class="header" v-show="!showBackBtn" :style="headerStyle">
      景点详情
      <div class="iconfont icon-back" @click="$router.back()">&#xe743;</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'detail-header',
  components: {
  },
  data() {
    return {
      showBackBtn: true,
      headerStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll() {
      let scrollTop = document.documentElement.scrollTop;
      if(scrollTop > 60) {
        this.showBackBtn = false;

        let opacity = scrollTop / 140;
        
        opacity = opacity > 1 ? 1  : opacity;
        this.headerStyle.opacity = opacity;
      }else {
        this.showBackBtn = true;
      }
    }
  },
  activated() {
    window.addEventListener('scroll', this.handleScroll);
  },
  deactivated() {
    window.removeEventListener('scroll', this.handleScroll);
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/variable.styl';

.banner-header
  .back-abs
    position absolute
    top .2rem
    left .2rem
    width .8rem
    height .8rem
    line-height .8rem
    text-align center
    border-radius 50%
    background rgba(0, 0, 0, .8)
    .icon-back
      color #fff
      font-size .6rem
  .header
    position fixed
    top 0
    left 0
    right 0
    z-index 1
    height .86rem
    line-height .86rem
    text-align center
    color #fff
    background $bgColor
    font-size .32rem
    .icon-back
      position absolute
      top 0
      left 0
      width .64rem
      text-align center
      font-size .6rem
</style>